package pruebaciudad.panels;

import pruebaciudad.formas.Figura;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import javax.swing.JPanel;

/**
 * @author Federico Vera <dktcoding [at] gmail>
 */
public class PanelTest extends JPanel implements ComponentListener {
    private static final long serialVersionUID = 76473599863546835L;
    public PanelDeDibujo internalPanel = new PanelDeDibujo();
    private int INTERNAL_PANEL_WIDTH  = 400;
    private int INTERNAL_PANEL_HEIGHT = 400;
    
    public PanelTest (int WIDTH, int HEIGHT){
        INTERNAL_PANEL_WIDTH  = WIDTH;
        INTERNAL_PANEL_HEIGHT = HEIGHT;
        
        initComponents();
    }

    @Override
    public void componentResized(ComponentEvent e) {
        centerPanel();
    }

    private void centerPanel() {
        internalPanel.setSize(INTERNAL_PANEL_WIDTH, INTERNAL_PANEL_HEIGHT);
        
        Dimension dimension = getSize();
        int xOffset = (dimension.width  - INTERNAL_PANEL_WIDTH)  / 2;
        int yOffset = (dimension.height - INTERNAL_PANEL_HEIGHT) / 2;
        
        internalPanel.setLocation(xOffset, yOffset);
    }

    @Override
    public void componentMoved(ComponentEvent e)  {}
    @Override
    public void componentShown(ComponentEvent e)  {}
    @Override
    public void componentHidden(ComponentEvent e) {}

    private void initComponents() {
        internalPanel.setBackground(Color.WHITE);
        addComponentListener(this);
        add(internalPanel);
        centerPanel();
    }
    
    public void dibujar(Figura forma) {
        internalPanel.agregarFigura(forma);
    }
    
}
